<template >
    <div>

        <div>
            <input type="text" v-model='cardtextData'>
            <button @click='useFatherFun'>这是cart4444444{{userData}}</button>
            <button @click='twoClick'>阻止连续点击事件</button>
            <button>{{timeData}}</button>
            <button>{{timer | dateFormat('yyyy.M.d')}}</button>
        </div>
    </div>

</template>
<script>
export default {
  name: "Cart4",
  props: {
    userData: {
      type: String,
      default: "你好"
    }
  },
  data() {
    return {
      timeNum: true, //true代表可以点击
      cardtextData: ``,
      userInfo: "",
      timeData: `2018-09-05T19:54:35.793+0800`,
      timer: `1536337991127`
    };
  },
  created() {
    let that = this;
    this.cardtextData = this.cardtext;
    this.userInfo = this.userData;
    console.log(`张`, this.cardtextData);

    //转时间搓
    // that.timeData = new Date(that.timeData);
    //将时间搓格式化为需要的时间格式
    // that.timeData = that.timeData.format("yyyy.MM.dd hh.mm.ss");
  },
  computed: {
    cardtext: function() {
      return this.$store.state.cardText;
    }
  },
  methods: {
    twoClick() {
      let that = this;
      console.log(`that.timeNum`, that.timeNum);
      if (!that.timeNum) {
        return;
      }
      that.timeNum = false;
      console.log(`我要做的事情`);
      setTimeout(() => {
        that.timeNum = true;
      }, 3000);
      console.log(`组阻止连续事件点击`);
    },
    childrenFun() {
      console.log(`这是子组件的方法`);
    },
    useFatherFun() {
      let that = this;
      console.log(`调用父组件的方法`);
      that.$emit(`useFatherFun`, 1);
    }
  },
  watch: {
    cardtextData: function(newVal, oldVal) {
      this.$store.commit(`changeTextData`, newVal);
    }
  }
};
</script>
